<?php 
setcookie('usn',"");
    setcookie('pwd',"");
include_once("function/database.php");
// $userName = $_POST['userName'];
// $password = $_POST['password'];
$userName = addslashes($_POST['userName']);
$password = addslashes($_POST['password']);
$remark = $_POST['remark'];
$json_string = file_get_contents('usr.json');

$d = json_decode($json_string,true);
if($userName==""){
if($remark!=null){
$d = json_decode($json_string,true);
	$d[$userName]['remark']="$remark";
        
        $json_strings = json_encode($d);
        file_put_contents("usr.json",$json_strings);
    echo "<script>window.location.href='index.php'</script>";
	
}else{
	echo "<script>window.location.href='login.html'</script>";
}
}
if($d[$userName]['pass']===$password){
    setcookie('usn',$userName);
    setcookie('pwd',$password);
    echo '登录成功！';
    echo "<script>window.location.href='index.php'</script>";

ob_end_flush();
}else{
	echo '用户名或密码错误！';
	echo "<a href='login.html'>重试</a>";
}
